package demo.mysql.java.connectivity;

import java.sql.*;
public class ConnectToMySQLSimple
{
	public ConnectToMySQLSimple(){}
	public Connection Open_ConnectDB()
	{
		String connectionURL = "jdbc:mysql://127.0.0.1:3306/";
		String NomDB = "Demo1";
		String driver = "com.mysql.jdbc.Driver";
		String userName = "root"; 
		String password = "123456";
		Connection connection = null;
		try
		{
			Class.forName(driver).newInstance();
			connection = DriverManager.getConnection(connectionURL+NomDB, userName, password);
			/*Statement st = connection.createStatement();
			ResultSet rs = st.executeQuery("select * from Nouvel");
			while (rs.next()) {
			    System.out.println("Merdemkj" + rs.getString(1));
			    System.out.println("99000" + rs.getString(2));
			} */   
		}
		catch(Exception ex){ex.printStackTrace();}
		return connection;
	}
	
	public void Close_ConnectDB(Connection conn)
	{
		if(conn!=null)
		{
			try
			{
				conn.close();
				System.out.println("Da out");
			}
			catch(Exception ex){}
		}
	}
	/*public static void main(String[] args) {
		ConnectToMySQLSimple p = new ConnectToMySQLSimple();
		//Open_ConnectDB();
		Connection conn = null;
		conn = p.Open_ConnectDB();
		p.Close_ConnectDB(conn);
		System.out.println("Ga con");
	}*/
	
}